﻿using System;

[assembly: CLSCompliant(true)]

namespace ViewModel
{
    using System.ComponentModel;
    using System.Linq;

    /// <summary>
    /// Base class for working with MVVM pattern
    /// </summary>
    [CLSCompliant(true)]
    public class ViewModelBase : INotifyPropertyChanged
    {
        #region Method Helpers

        /// <summary>
        /// Converts string to unicode format
        /// </summary>
        /// <param name="unknown"></param>
        /// <returns></returns>
        public static string ToUtf8(string unknown)
        {
            return new string(unknown.ToCharArray().Select(x => ((x + 848) >= 'А' && (x + 848) <= 'ё') ? (char)(x + 848) : x).ToArray());
        }

        /// <summary>
        /// Checks if passing object is null, if yes - return unknown.
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns>
        /// string
        /// </returns>
        public string CheckUnknow(object parameter)
        {
            if (parameter != null)
            {
                return (string)parameter;
            }

            return "Unknown";
        }

        #endregion

        #region INotifyPropertyChanged Members

        /// <summary>
        /// Event for mvvm
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Method for information of changes in vm
        /// </summary>
        /// <param name="propertyName"></param>
        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
